499c1542835401f1631219a80d6b0387872ad59a,platform/util/src/com/intellij/execution/rmi/RemoteUtil.java,RemoteUtil,castToLocal,#Object#Class#,62
Before Change
public static <T> T castToLocal(final Object remote, final Class<T> clazz) {
final ClassLoader loader = clazz.getClassLoader();
Object proxy = Proxy.newProxyInstance(loader, new Class[]{clazz}, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass() == Object.class) {
return method.invoke(remote, args);
}
else {
Method m = ourRemoteToLocalMap.get(Pair.<Class<?>, Class<?>>create(remote.getClass(), clazz)).get(method);
if (m == null) throw new NoSuchMethodError(method.getName() + " in " + remote.getClass());
try {
Object result = m.invoke(remote, args);
if (result instanceof Remote) {
return castToLocal(result, tryFixReturnType(result, method.getReturnType(), loader));
}
return result;
}
catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) throw cause;
if (cause instanceof Error) throw cause;
if (canThrow(cause, method)) throw cause;
throw new RuntimeException(cause);
}
}
}
});
return (T)proxy;
}
private static Class<?> tryFixReturnType(Object result, Class<?> returnType, ClassLoader loader) throws Exception {
After Change
public static <T> T castToLocal(final Object remote, final Class<T> clazz) {
final ClassLoader loader = clazz.getClassLoader();
//noinspection unchecked
return (T)Proxy.newProxyInstance(loader, new Class[]{clazz}, new RemoteInvocationHandler(remote, clazz, loader));
}
private static Class<?> tryFixReturnType(Object result, Class<?> returnType, ClassLoader loader) throws Exception {